package advance

import (
	"context"
	"fmt"

	"go.mongodb.org/mongo-driver/bson"
	"go.mongodb.org/mongo-driver/mongo"
)

func Group(mongo *mongo.Database, ctx context.Context) {
	pipeline := bson.A{bson.M{"$group": bson.M{"_id": nil, "count": bson.M{"$count": bson.M{}}}}}
	temp, err := mongo.Collection("test").Aggregate(ctx, pipeline)
	fmt.Println(err)
	for temp.TryNext(ctx) {
		fmt.Println(temp.Current)
	}
}

func Group1(mongo *mongo.Database, ctx context.Context) {
	pipeline := bson.A{bson.M{"$group": bson.M{"_id": "$int32", "count": bson.M{"$count": bson.M{}}}}}
	temp, err := mongo.Collection("test").Aggregate(ctx, pipeline)
	fmt.Println(err)
	for temp.TryNext(ctx) {
		fmt.Println(temp.Current)
	}
}

func Group2(mongo *mongo.Database, ctx context.Context) {
	pipeline := bson.A{bson.M{"$group": bson.M{"_id": nil, "push": bson.M{"$push": "$text"}}}}
	temp, err := mongo.Collection("test").Aggregate(ctx, pipeline)
	fmt.Println(err)
	for temp.TryNext(ctx) {
		fmt.Println(temp.Current)
	}
}
